/**   
 * Copyright © 2018 Zuxia. Tech Ltd. All rights reserved.
 * 
 * @Package: com.java46.struts2.base.action 
 * @author: zuxia   
 * @date: 2018年7月4日 上午10:07:06 
 */
package com.java46.struts2.base.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.java46.struts2.base.entity.GenericResult;
import com.opensymphony.xwork2.ActionSupport;

/** 
 * @ClassName: BaseAction 
 * @Description: TODO
 * @author: zuxia
 * @date: 2018年7月4日 上午10:07:06 
 */
@ParentPackage(value = "pkg")
@Namespace(value = "/")
@Results(value = {
		// 普通请求异常跳转地址
		@Result(name = "input", location = "/error.jsp"),
		// ajax请求异常跳转地址
		@Result(name="json", type="json", params = {"root", "result"})
		}
)

public abstract class BaseAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {
	/** 序列化ID **/
	private static final long serialVersionUID = 3235012245282152539L;
	
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
	protected void setSessionAttribute(String key, Object value) {
		HttpSession session = request.getSession();
		session.setAttribute(key, value);
	}
	
	protected Object getSessionAttribute(String key) {
		HttpSession session = request.getSession();
		return session.getAttribute(key);
	}
	
	protected GenericResult result;
	public GenericResult getResult() {

		return result;
	}
	public void setResult(GenericResult result) {

		this.result = result;
	}
	public void setSuccesResult(Object obj) {
		result = new GenericResult();
		result.setSuccess(true);
		result.setData(obj);
	}
}